package com.ruoyi.web.controller.comprehensive;

import com.ruoyi.comprehensive.domain.Drawing;
import com.ruoyi.comprehensive.service.IDrawingService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 图纸管理Controller
 * 
 * @author hcc
 * @date 2023-12-12
 */
@RestController
@RequestMapping("/comprehensive/drawing")
public class DrawingController extends BaseController
{
    @Autowired
    private IDrawingService drawingService;

    /**
     * 查询图纸管理列表
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:drawing:list')")
    @GetMapping("/list")
    public TableDataInfo list(Drawing drawing)
    {
        startPage();
        List<Drawing> list = drawingService.selectDrawingList(drawing);
        return getDataTable(list);
    }

    /**
     * 导出图纸管理列表
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:drawing:export')")
    @Log(title = "图纸管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Drawing drawing)
    {
        List<Drawing> list = drawingService.selectDrawingList(drawing);
        ExcelUtil<Drawing> util = new ExcelUtil<Drawing>(Drawing.class);
        util.exportExcel(response, list, "图纸管理数据");
    }

    /**
     * 获取图纸管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:drawing:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(drawingService.selectDrawingById(id));
    }

    /**
     * 新增图纸管理
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:drawing:add')")
    @Log(title = "图纸管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Drawing drawing)
    {
        return toAjax(drawingService.insertDrawing(drawing));
    }

    /**
     * 修改图纸管理
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:drawing:edit')")
    @Log(title = "图纸管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Drawing drawing)
    {
        return toAjax(drawingService.updateDrawing(drawing));
    }

    /**
     * 删除图纸管理
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:drawing:remove')")
    @Log(title = "图纸管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(drawingService.deleteDrawingByIds(ids));
    }

    /**
     * 获取待审核列表
     * @return
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:drawing:query')")
    @GetMapping("/getReviewList")
    public TableDataInfo getReviewList(Drawing drawing){
        startPage();
        List<Drawing> list = drawingService.getReviewList(drawing);
        return getDataTable(list);
    }
    /**
     * 获取图纸台账（通过审核）
     * @return
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:drawing:query')")
    @GetMapping("/getLedgerList")
    public TableDataInfo getLedgerList(Drawing drawing){
        startPage();
        List<Drawing> list = drawingService.getLedgerList(drawing);
        return getDataTable(list);
    }
    /**
     * 获取历史图纸信息
     * @return
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:drawing:query')")
    @GetMapping("/getHistory/{historyId}")
    public TableDataInfo getHistory(@PathVariable("historyId") Long historyId){
        List<Drawing> list = drawingService.getHistory(historyId);
        return getDataTable(list);
    }
}
